package com.charonmc.commands;

import com.charonmc.utils.VanishUtils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class Vanish implements CommandExecutor {
    @Override
    public boolean onCommand(CommandSender sender, Command cmd,String label,String[] args) {
        if (!sender.hasPermission("Core.Vanish")) {
            if (sender instanceof Player) {
                return true;
            }
        } else {
            //单独使用命令
            if (args.length == 0) {
                if (!(sender instanceof Player)) {
                    return true;
                } else {
                    Player player = (Player) sender;
                    //在这写主要内容
                    if (VanishUtils.getVanishPlayers().contains(player)){
                        VanishUtils.removePlayerVanish(player);
                        sender.sendMessage("§b§l您的隐身模式已§c§l关闭");
                    } else {
                        VanishUtils.setPlayerVanish(player);
                        sender.sendMessage("§b§l您的隐身模式已§a§l开启");
                    }


                }
            }
            //带参数，但参数只能有一个
            else if (args.length == 1) {
                if (args[0].equals("list")) {
                    sender.sendMessage("§al以下是子服所有隐身玩家(Nicked)：");
                    sender.sendMessage("§b§l=================================");
                    for (Player x : VanishUtils.getVanishPlayers()) {
                        sender.sendMessage("§e§l" + x.getDisplayName());
                    }
                    sender.sendMessage("§b§l=================================");
                } else {
                    sender.sendMessage("§c§l参数错误！");
                }
            } else {
                //参数太多
                sender.sendMessage("§c§l参数错误！");
            }
        }
        return true;
    }
}
